import csv
import matplotlib.pyplot as plt
from datetime import datetime

filename = 'data/sitka_weather_2018_simple.csv'

with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)

    # 从文件中获取最高温度
    dates,highs,lows = [],[],[]
    for row in reader:
        high = int(row[5])
        low = int(row[6])
        current_date = datetime.strptime(row[2],'%Y-%m-%d')
        #华氏度转摄氏度
        chigh = 5*(high-32)/9
        clow = 5*(low-32)/9
        highs.append(chigh)
        dates.append(current_date)
        lows.append(clow)

#绘制最高温度气温
plt.style.use("seaborn",)
fig,ax=plt.subplots(dpi=128)
ax.plot(dates,highs,c='red',alpha=0.5)
ax.plot(dates,lows,c='blue',alpha=0.5)
ax.fill_between(dates,lows,highs,facecolor='blue',alpha=0.1)

#设置图形格式
ax.set_title('The highest temperature during July',fontsize=24)
ax.set_xlabel('',fontsize=14)
fig.autofmt_xdate()
ax.set_ylabel("Temperature(C)",fontsize=16)
ax.tick_params(axis='both',which='major',labelsize=16)

plt.show()